window.name = "NG_DEFER_BOOTSTRAP!";
init = false;
$('#dataGrid').datagrid({
	url : PATH + '/business/dbbackup/list',
	fit : true,
	fitColumns : true,
	border : false,
	pagination : true,
	idField : 'id',
	pageSize : 10,
	pageList : [ 10, 20, 30, 40, 50 ],
	sortName : 'createtime',
	sortOrder : 'desc',
	checkOnSelect : false,
	selectOnCheck : false,
	nowrap : false,
	striped : true,
	rownumbers : true,
	singleSelect : true,
	frozenColumns : [ [ {
		field : 'id',
		title : '编号',
		width : 150,
		hidden : true
	}, {
		field : 'createuser',
		title : '创建者',
		width : 120,
		sortable : true
	} ] ],
	columns : [ [ {
		field : 'filename',
		title : '文件名',
		width : 120,
		sortable : true
	},{
		field : 'filepath',
		title : '路径',
		width : 150,
		hidden : true
	}, {
		field : 'createtime',
		title : '创建时间',
		width : 120,
		sortable : true
	}, {
		field : 'action',
		title : '操作',
		width : 100,
		formatter : formatterFun
	} ] ],
	toolbar : '#toolbar',
	onLoadSuccess : function() {
		parent.$.messager.progress('close');
		$(this).datagrid('tooltip');

		if (!init) {
			console.log("出");
			angular.resumeBootstrap();
			init = true;
		}
	},
	onRowContextMenu : function(e, rowIndex, rowData) {
		e.preventDefault();
		$(this).datagrid('unselectAll');
		$(this).datagrid('selectRow', rowIndex);
		$('#menu').menu('show', {
			left : e.pageX,
			top : e.pageY
		});
	}
});

MainApp.controller('DbbackCtrls', [ '$scope', function($scope) {

	$scope.load = function() {
		console.log("13");

	};

	$scope.createNote = function() {
		console.log("12");

	};

	$scope.createReadOnlyNote = function() {
		console.log("10");

	};

	$scope.statusFun = function() {
		console.log("9");

	};
	$scope.downloadFun = function(id) {
		if (id == undefined) {
			var rows = $('#dataGrid').datagrid('getSelections');
			id = rows[0].id;
		}
		console.log(id + "下载");

		window.open(PATH + "/business/dbbackup/download?id=" + id);

	};

	$scope.submitStatus = function() {
		console.log("8");

	};

	$scope.deleteFun = function() {
		console.log("7");

	};
	$scope.backupnowFun = function() {
		console.log("马上备份");
		parent.$.messager.confirm('询问', '是否马上执行备份？', function(b) {
			if (b) {
				parent.$.messager.progress({
					title : '提示',
					text : '正在备份中，请稍后....'
				});
				$.post(PATH+'/business/dbbackup/backupnow', {
					
				}, function(result) {
					if (result.success) {
						window.open(PATH + "/business/dbbackup/download?id=" + result.data);
					}
					parent.$.messager.progress('close');
				}, 'JSON');
			}
		});
	};
	$scope.restoreFun = function(filepath) {
		console.log("还原");
		var rows = $('#dataGrid').datagrid('getSelections');
		console.log(rows);
		filepath = rows[0].filepath;
		parent.$.messager.confirm('询问', '是否马上执行还原？', function(b) {
			if (b) {
				parent.$.messager.progress({
					title : '提示',
					text : '正在还原中，请稍后....'
				});
				$.post(PATH+'/business/dbbackup/restore', {
					filepath:filepath
				}, function(result) {
					
					parent.$.messager.progress('close');
						alert(result.data);
					
				}, 'JSON');
			}
		});
	};

	$scope.viewFun = function() {
		console.log("6");

	};
	$scope.saveSettingFun = function() {
		console.log("6");

	};

	$scope.editFun = function() {
		console.log("5");

	};

	$scope.addFun = function() {
		console.log("4");

	};

	$scope.submit = function() {
		console.log("3");

	};

	$scope.searchFun = function() {
		console.log("2");

	};
	$scope.cleanFun = function() {
		console.log("1");

	};

	$scope.fileManage = function() {

		console.log('load ');

	};

} ]);